<template>
    <div class="icons">
      <swiper :options="swiperOption">
        <!-- slides -->
        <swiper-slide v-for="(page, index) in pages" :key="index">
          <div class="icon" v-for="item in page" :key="item.id">
            <img class="icon-img" :src="item.imgUrl" alt="">
            <p class="icon-title">{{item.title}}</p>
          </div>
        </swiper-slide>
      </swiper>
    </div>
</template>

<script>
export default {
  name: 'Icons',
  props: {
    iconsList: Array
  },
  data () {
    return {
      swiperOption: {
        pagination: '.swiper-pagination'
      }
    }
  },
  computed: {
    pages () {
      const pages = []
      this.iconsList.forEach((item, index) => {
        const page = Math.floor(index / 8)
        if (!pages[page]) {
          pages[page] = []
        }
        pages[page].push(item)
      })
      return pages
    }
  }
}
</script>

<style lang="stylus" scoped>
  @import "~css/varibles.styl"
  @import "~css/mixins.styl"
  .icons
    overflow :hidden
    padding-top: 0.2rem
    .icon
      width: 25%
      float :left
      display :flex
      flex-direction :column
      justify-content :flex-start
      align-items :center
      margin-bottom: 0.2rem
      .icon-img
        width :50%
        height :50%
        margin-bottom: 0.14rem
      .icon-title
        width :100%
        text-align :center
        font-size :0.28rem
        color :$darkTextColor
        ellipsis ()
</style>
